﻿using System.Windows;
using PokemonRegister.ViewModel;

using Framework;
using System.Net;
using hMailServer;

namespace PokemonRegister
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        /// <summary>
        /// Initializes a new instance of the MainWindow class.
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();
            Closing += (s, e) => ViewModelLocator.Cleanup();
        }

        private void button_Click(object sender, RoutedEventArgs e)
        {
            CookieContainer cookies = new CookieContainer();
            string result = HttpUtil.Html("https://club.pokemon.com/us/pokemon-trainer-club/sign-up/", cookies);

            string username = "jonney858";
            string pwd = "sa3f21263f51a3s";
            var token = cookies.GetCookie("csrftoken").Value;
            var email = "jonney858@neect.com";

            result = HttpUtil.Html("https://club.pokemon.com/us/pokemon-trainer-club/sign-up/", cookies,
                new
                {
                    csrfmiddlewaretoken = token,
                    dob = "1990-01-01",
                    undefined = "1990",
                    country = "US"
                }
            , true);
            var contentType = HttpUtil.ContentType;
            HttpUtil.ContentType = "application/json";
            result = HttpUtil.Html("https://club.pokemon.com/api/signup/verify-username", cookies,
                new
                {
                    name = username
                }.ToJson()
            , true);

            result = HttpUtil.Html("https://club.pokemon.com/api/profile/verify-screenname", cookies,
                new
                {
                    name = username
                }.ToJson()
            , true);
            HttpUtil.ContentType = contentType;
            result = HttpUtil.Html("https://club.pokemon.com/us/pokemon-trainer-club/parents/sign-up", cookies,
                new
                {
                    csrfmiddlewaretoken = token,
                    username = username,
                    password = pwd,
                    confirm_password = pwd,
                    email = email,
                    confirm_email = email,
                    public_profile_opt_in = true,
                    screen_name = username,
                    terms = "on"
                }
            , true);
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            ApplicationClass application = new ApplicationClass();
            application.Authenticate("administrator", "q5596152");
            Account ac = application.Domains.ItemByName["neect.com"].Accounts.Add();
            ac.Address = "jonney832@neect.com";
            ac.Password = "a1fw6e5f16aw";
            ac.Save();
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            CookieContainer cookies = new CookieContainer();
           string result =  HttpUtil.Html("http://mail.neect.com/create.php", cookies, "username=jonneydong&password=f239hfq298h3f", true);
        }
    }
}